﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LineImageCtr : MonoBehaviour {
    public GameObject mainBall;
    RectTransform rect;

	// Use this for initialization
	void Start () {
        rect = this.GetComponent<RectTransform>();
        rect.anchoredPosition3D = mainBall.GetComponent<RectTransform>().anchoredPosition3D / 2;
        rect.sizeDelta = new Vector2(1.0f, Vector3.Distance(Vector3.zero, mainBall.GetComponent<RectTransform>().anchoredPosition3D));
	}
	
	// Update is called once per frame
	void LateUpdate () {
        if (mainBall)
        {
            rect.anchoredPosition3D = mainBall.GetComponent<RectTransform>().anchoredPosition3D / 2;
            rect.eulerAngles = new Vector3(0, 0, 180.0f / Mathf.PI * Mathf.Atan2(mainBall.GetComponent<RectTransform>().anchoredPosition3D.y, mainBall.GetComponent<RectTransform>().anchoredPosition3D.x));
            rect.sizeDelta = new Vector2(Vector3.Distance(Vector3.zero, mainBall.GetComponent<RectTransform>().anchoredPosition3D), 3.0f);
        }
        else
        {
            Destroy(gameObject);
        }
    }
}
